#include <stdio.h>
#include <stdlib.h>

typedef int Length;

typedef struct { Length x, y, z; } vec3D;

static int compareVectors(const void *p1, const void *p2)
{
	vec3D *v1 = (vec3D *)p1;
	vec3D *v2 = (vec3D *)p2;
	if(v1->x < v2->x) return -1;
	if(v1->x > v2->x) return 1;
	if(v1->y < v2->y) return -1;
	if(v1->y > v2->y) return 1;
	if(v1->z < v2->z) return -1;
	return 0;
}

int main( int argc, const char* argv[] )
{
	vec3D v1 = {12, 1, -3};
	vec3D v2 = {12, 2, 3};
	vec3D v3 = {12, 3, 45};
	vec3D v4 = {6, 5, 3};
	vec3D v5 = {-4, 8, -73};
	vec3D v6 = {-5, 6, 45};
	vec3D v7 = {-5, 45, -3};
	vec3D v8 = {12, 2, 78};
	vec3D v9 = {154, 45, 3};
	vec3D v10 = {12, 2, 12};
	vec3D v11 = {12, 3, 3};
	vec3D v12 = {6, 22, -21};
	vec3D vectors[] = {v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12};
	qsort(vectors, 12, sizeof(vec3D), compareVectors);
	
	FILE *file;
	file = fopen("list.txt", "w");
	int i;
	for(i = 0; i < 12; i++)
	{
		fprintf(file, "vector at index %d: (%d, %d, %d)\n", i, vectors[i].x, vectors[i].y, vectors[i].z);
	}
	fclose(file);	
	return 0;
}
